package main

import (
	"fmt"
	"math/rand"
	"time"
)

//判断数组是否从小到大
func isOrder(arr []int) bool {
	for i := 1; i < len(arr); i++ {
		if arr[i-1] > arr[i] {
			return false
		}
	}
	return true
}

func randList(arr []int) {
	data := make([]int, len(arr)) //新建一个数组

	copy(data, arr)                  //拷贝数组
	rand.Seed(time.Now().UnixNano()) //定义随机数种子

	index := rand.Perm(len(arr)) //随机选择一个切片

	// fmt.Println(index)

	for i, k := range index {
		arr[i] = data[k]
	}
}

func main() {
	list := []int{11, 29, 24, 85, 300, 70}

	fmt.Println(list)
	count := 0
	for {
		if isOrder(list) {
			fmt.Println("排序完成：", list)
			break
		} else {
			randList(list)
			count++
		}
	}

	fmt.Println(count)
}
